﻿define('data/users', ['data', 'loc', 'root'], function (data, loc, root) {

    var User = function (fromServer) {
        fromServer = fromServer || {};
        var self = this;
        self.Id = fromServer.Id || 0;
        self.FirstName = ko.observable(fromServer.FirstName).extend({ required: true });
        self.LastName = ko.observable(fromServer.LastName).extend({ required: true });
        self.Description = ko.observable(fromServer.Description);
        self.Email = ko.observable(fromServer.Email).extend({ email: true, required: true });
        self.Role = ko.observable(fromServer.Role).extend({ required: true });
        self.RoleName = ko.observable(fromServer.RoleName);
        self.Password = ko.observable('');
        if (self.Id == 0) {
            self.Password.extend({ required: true });
        }
        self.PasswordConfirm = ko.observable('').extend({
            equalTo: {
                message: loc.Validation_PasswordConfirm,
                params: {
                    model: self,
                    prop: 'Password'
                }
            }
        });
    };

    var ListUser = function(fromServer) {
        $.extend(this, fromServer);
        this.isDeleting = ko.observable(false);
        var addDate = moment(this.CreateDate);
        this.CreateDate = addDate.format('MMMM Do YYYY');
    };

    return $.extend(new data.Crud('users'), {
        User: User,
        ListUser: ListUser,
        RolesLink: root + 'users/getroles'
    });
});